<template>
	<view :class="isDark?'darkBg':''">
		<cu-custom :bgColor="isDark?'bg-black':'bg-green'" isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">查题答案</block>
		</cu-custom>
		<view :class="isDark?'dark':''">
			<view>
				<view style="height: 545rpx; background-size: cover;  background-position: center;"
					:style="{backgroundImage:isDark?'url(https://web.cloudduolc.cn/image/adblack7.png)':'url(https://web.cloudduolc.cn/image/adwhite5.png)'}">

					<ad unit-id="adunit-65dd16a091c0d59f" ad-type="video" :ad-theme="isDark?'black':'white'"></ad>
				</view>
				<view class="cu-bar  solid-bottom" style="font-weight:bold" :class="isDark?'dark':'bg-white'">
					<view class="action">
						<text class="cuIcon-titles text-green"></text> 查题答案
						<text class="cuIcon-search"></text>
					</view>
				</view>

				<view class="cu-form-group solid-bottom" :class="isDark?'dark':'bg-white'">
					<textarea maxlength="-1" :disabled="modalName!=null" @input="searchIcon" placeholder="输入关键词"
						:value="key" name="key"></textarea>
					<button class='cu-btn bg-green shadow' @click="refreshInfo()" v-if="is_show">搜索</button>
					<button class='cu-btn bg-green shadow' disabled v-if="!is_show">搜索</button>
				</view>




				<view v-show="showEmptyIcon" style="text-align: center;font-size: 40rpx;margin-top: 20rpx;"
					:class="isDark?'darkIn':'bg-white'">


					<image src="../../../static/score/empty.png" style="width: 600rpx;height: 600rpx;margin-top: 0rpx;">
					</image>
				</view>
				<view class=" margin padding" :class="isDark?'darkIn':'bg-white'" v-show="!showEmptyIcon">
					<view style="display: flex;">


						<view>
							<view style="margin-top: 20rpx;margin-left: 65rpx; word-break:break-all;">
								题目：{{totalList.question}}
							</view>
							<view style="margin-top: 20rpx;margin-left: 65rpx; word-break:break-all;">
								答案：{{totalList.answer}}
							</view>

						</view>
					</view>
				</view>

			</view>
		</view>
		<zmm-watermark>

		</zmm-watermark>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				array: [],
				index: 0,
				totalList: [],
				total: null,
				num: null,
				showEmptyIcon: true,
				isDark: this.isDark,
				page: 1,
				key: '',
				is_show: true,


			}
		},
		onLoad(option) {
			console.log(option)
			// if (option.key) {
			// 	this.key = option.key
			// 	this.cleanData()
			// 	this.refreshInfo()
			// }

		},
		onShow() {
			let _this = this


		},
		methods: {
			searchIcon(e) {
				let _this = this

				let key = e.detail.value;
				_this.key = key
				//console.log(key)

			},

			cleanData() {
				let _this = this
				_this.totalList = []
			},
			show() {
				this.is_show = true
			},
			// toSearch() {
			// 	this.is_show = false
			// 	if (this.key.length <= 0) {
			// 		uni.showToast({
			// 			icon: 'none',
			// 			title: '关键词为空！',
			// 			duration: 2000
			// 		});

			// 	} else {

			// 		this.$Router.redirectTo("/pages/custom/question/search?key=" + this.key)

			// 	}
			// 	setTimeout(this.show, 1000)

			// },
			/**
			 * @description  请求数据
			 */
			refreshInfo: function() {
				let _this = this
				var userInfo = _this.$store.state.userInfo
				if (_this.$store.state.isExit == 1 | userInfo.password == "" || userInfo.password == null) {

					uni.showModal({
						title: 'Hi',
						content: '会话已过期，\n当前功能需要登录，是否要去登录?\n(该程序的用户信息只存在手机本地，当切出程序需要重新登录)',
						confirmText: "去登录",
						cancelText: "再逛会",
						success: function(res) {
							if (res.confirm) {
								_this.$Router.navigateTo("/pages/bind/login/index")
							} else if (res.cancel) {
								console.log("点击了取消")
							} else {
								console.log("点击了别的")
							}
						}
					});
					return
				}

				let form = {
					key: _this.key
				}

				_this.$schoolApi.searchQuestion(form).then(response => {
					//console.log(response.data)
					if (response.status == 0) {


						_this.totalList = response.data

						if (response.status == 0) {
							_this.showEmptyIcon = false
							uni.showToast({
								icon: 'none',
								title: '成功获取数据！',
								duration: 2000
							});
						} else {
							_this.showEmptyIcon = true
							uni.showToast({
								icon: 'none',
								title: response.msg,
								duration: 2000
							});
						}

					} else if (response.status != 608 && response.status != 603) {
						uni.showModal({
							title: '提示',
							content: response.msg,
							showCancel: false,
							success: function(res) {
								if (res.confirm) {

								} else if (res.cancel) {

								}
							}
						});
					}

				})



			}




		}

	}
</script>

<style>
	.tableTitle {
		float: right;
		margin-right: 50rpx;
		margin-top: 0rpx;
		width: 100rpx;
		font-size: 25rpx;
	}
</style>
